<?php

namespace app\proxy\model\plus\coupon;

use app\common\model\plus\coupon\UserCoupon as UserCouponModel;

class UserCoupon extends UserCouponModel
{

    /**
     * 获取优惠券列表
     */
    public function getList($limit = 20,$regionIds=[])
    {
        return $this->alias('userCoupon')->with(['user'])
            ->join('coupon', 'coupon.coupon_id = userCoupon.coupon_id', 'left')
            ->where(function ($query) use ($regionIds) {
                $query->whereIn('coupon.county_id', $regionIds)->whereOr("coupon.province_id", "in", $regionIds)->whereOr("coupon.city_id", "in", $regionIds);
            })
            ->order(['userCoupon.create_time' => 'desc'])
            ->paginate($limit);
    }
}